package com.haixiaoke.saas.enterprise.workOrder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.workOrder.domain.WorkOrderChargeItem;
import com.haixiaoke.saas.workOrder.service.IWorkOrderChargeItemService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 维修收费项目Controller
 * 
 * @author panda
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/enterprise/workOrder/chargeItem")
public class EnterpriseWorkOrderChargeItemController extends BaseController {
    @Autowired
    private IWorkOrderChargeItemService workOrderChargeItemService;

    /**
     * 查询维修收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderChargeItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderChargeItem workOrderChargeItem) {
        startPage();
        List<WorkOrderChargeItem> list = workOrderChargeItemService.selectWorkOrderChargeItemList(workOrderChargeItem);
        return getDataTable(list);
    }

    /**
     * 导出维修收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderChargeItem:export')")
    @Log(title = "维修收费项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkOrderChargeItem workOrderChargeItem) {
        List<WorkOrderChargeItem> list = workOrderChargeItemService.selectWorkOrderChargeItemList(workOrderChargeItem);
        ExcelUtil<WorkOrderChargeItem> util = new ExcelUtil<WorkOrderChargeItem>(WorkOrderChargeItem.class);
        util.exportExcel(response, list, "维修收费项目数据");
    }

    /**
     * 获取维修收费项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderChargeItem:query')")
    @GetMapping(value = "/{workOrderChargeItemId}")
    public AjaxResult getInfo(@PathVariable("workOrderChargeItemId") Long workOrderChargeItemId) {
        return success(workOrderChargeItemService.selectWorkOrderChargeItemByWorkOrderChargeItemId(workOrderChargeItemId));
    }

    /**
     * 新增维修收费项目
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderChargeItem:add')")
    @Log(title = "维修收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrderChargeItem workOrderChargeItem) {
        return toAjax(workOrderChargeItemService.insertWorkOrderChargeItem(workOrderChargeItem));
    }

    /**
     * 修改维修收费项目
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderChargeItem:edit')")
    @Log(title = "维修收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderChargeItem workOrderChargeItem) {
        return toAjax(workOrderChargeItemService.updateWorkOrderChargeItem(workOrderChargeItem));
    }

    /**
     * 删除维修收费项目
     */
    @PreAuthorize("@ss.hasPermi('enterprise:workOrderChargeItem:remove')")
    @Log(title = "维修收费项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workOrderChargeItemIds}")
    public AjaxResult remove(@PathVariable Long[] workOrderChargeItemIds) {
        return toAjax(workOrderChargeItemService.deleteWorkOrderChargeItemByWorkOrderChargeItemIds(workOrderChargeItemIds));
    }
}
